package com.it.sun.yuebike.framework.util;

import com.it.sun.yuebike.framework.constant.ResponseCode;
import com.it.sun.yuebike.framework.constant.ResponseMsg;
import com.it.sun.yuebike.framework.model.dto.Result;

/**
 * @ClassName com.it.sun.yuebike.framework.util.ResultUtils
 * @Author sunmannian
 * @Date 2021/5/31 14:32
 * @Version V1.0
 * Description  <相应内容工具类>
 * Copyright (C) 北京中电兴发科技有限公司  since 2021/5/31
 */
public final class ResultUtils {

    public static Result success() {
        return Result.builder()
                .code(ResponseCode.SUCCESS)
                .msg(ResponseMsg.SUCCESS)
                .build();
    }


    public static <T> Result<T> success(T data) {
        return error(data, ResponseCode.SUCCESS, ResponseMsg.SUCCESS);
    }

    public static <T> Result<T> success(T data, String code, String msg) {
        return (Result<T>) Result.builder()
                .code(code)
                .msg(msg)
                .data(data)
                .build();
    }

    public static Result error() {
        return error(ResponseCode.FAILED);
    }

    public static Result error(String msg) {
        return error(ResponseCode.FAILED, msg);
    }

    public static Result error(String code, String msg) {
        return Result.builder()
                .code(code)
                .msg(msg)
                .build();
    }


    public static <T> Result<T> error(T data) {
        return error(data, ResponseCode.FAILED, ResponseMsg.FAILED);
    }

    public static <T> Result<T> error(T data, String code, String msg) {
        return (Result<T>) Result.builder()
                .code(code)
                .msg(msg)
                .data(data)
                .build();
    }

}



